<template>
  <div id="app" style="width: 100%; height: 100%;">
    <el-container style="user-select: none; height: 100%; width: 100vw; background-color: #f2f1ff;">
      <el-container style="height: 100%;">
          <div 
              v-if="leftMenuStore.isShowLeftMenu"
              style="height: 100%; background-color: #6A5ACD;"
              :style="{ 'width': isCollapse ? '64px' : '200px' }"
          >
              <LeftMenuComponent />
          </div>
          <el-main :style="{ width: isCollapse ? '85%' : '100vw'}">
              <RouterView />
          </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script setup>
import { RouterLink, RouterView, useRouter } from 'vue-router'
import { onBeforeMount, watch, ref } from 'vue'
import { ElNotification, } from 'element-plus';
import { Expand, Fold, Service } from '@element-plus/icons-vue'

// component
import LeftMenuComponent from './LeftMenu.vue'

// store
import { leftMenuStore, systemRouterStore, globalLoading } from '@/store/app.js'
import { checkLogin } from '@/store/LoginUser'
import { notCheckLoginPath, notContactServicePath } from '@/router/index.js'

const load = ref(false)
watch(
    () => {
        showFeed();
        return globalLoading.loading;
    },
    value => {
        load.value = value;
    },
    { deep: true, immediate: true }
)

const routerInstance = useRouter();
watch(
    () => routerInstance.currentRoute.value.path,
    value => showFeed(value),
    { deep: true, immediate: true }
)



const isCollapse = ref(false)

onBeforeMount(async () => {
    // let path = window.location.pathname
    // if(path == '/') {   //如果是官网，则需要检查是否登录，但不需要阻塞系统加载（直接进入）
    //     checkLogin()
    // } else if(notCheckLoginPath.includes(path)) { 
    // } else if(!path.includes("/login")) {   //如果其他页面（系统内），则需要阻塞并检查是否登录（排除登录页面）
    //     globalLoading.openGlobalLoading()
    //     if(!await checkLogin()) {
    //         routerInstance.push({ path: '/login' });
    //     }
    // }
})

const feedbackDialogVisible = ref(false)
const feedback = ref('')
const phone = ref('')
function sendFeedback() {
    if (phone.value != undefined && phone.value != null && phone.value.length > 0) {
        let regPhone = /^1[3456789]\d{9}$/;
        if (!regPhone.test(phone.value)) {
            ElNotification({
                title: '问题与反馈',
                message: '请输入正确的手机号',
                type: 'warning',
            })
            return;
        }
    }

    addFeedAPI({
        feedback: feedback.value,
        phone: phone.value
    }, resp => {
        if (resp) {
            feedback.value = "";
            phone.value = "";
            feedbackDialogVisible.value = false;
        }
    })
}
</script>
<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
